﻿package nl.stroep.classbuilder.app
{
	import fl.controls.TextArea;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.text.TextFormat;
	import nl.stroep.classbuilder.codeformatter.CodeFormatter;
	import nl.stroep.classbuilder.project.ProjectManager;
	
	/**
	 * ...
	 * @author Mark Knol
	 */
	public final class TestProjectLoader extends Sprite 
	{
		private var projectManager:ProjectManager = ProjectManager.getInstance(); 
		
		public function TestProjectLoader():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			projectManager.addEventListener(Event.COMPLETE, onProjectLoaded);
			projectManager.load();
		}
		
		private function onProjectLoaded(e:Event):void 
		{
			trace(projectManager.current.classes.length);
			
			var textfield:TextArea = new TextArea();
			textfield.textField.defaultTextFormat = new TextFormat("Consolas", 11, 0, false);
			textfield.condenseWhite = true;
			
			for (var i:int = 0; i < projectManager.current.classes.length; ++i) 
			{
				textfield.appendText( CodeFormatter.format( projectManager.current.classes[i].toString() ) )
				textfield.appendText("\n------------------------------------------------------------------------------\n\n\n\n")
			}
			
			textfield.width = stage.stageWidth;
			textfield.height = stage.stageHeight;
			textfield.wordWrap = true;
			this.addChild(textfield);
			
		}
		
	}
	
}